#include "common.h"
S4B VAToLA(PPROCESS process,U4B VA)
{
   if(((S4B)ReenterKernel)>0) return VA;  /*In the interrupt*/
   if(process->p_ppde==(PPDE)PTR_INVALID) return VA;    /*In the server*/
   //  if((U4B)process==0xA00000)Print("USER ADDRESS TRANSLATE %X",process->p_ppde);
   //return (((((PPTE)((process->p_ppde->pde[(((U4B)(VA>>22))&0x3FF)])&0xFFFFF000))->pte[((VA>>12)&0x3FF)])&0xFFFFF000)+(VA & 0xFFF));
   return (((((PPTE)((process->p_ppde->pde[VA>>22])&0xFFFFF000))->pte[(VA>>12)&0x3FF])&0xFFFFF000)+(VA & 0xFFF));/*In the usr process*/
}
PUBLIC S4B InitUserPDEAndPTE(PPDE ppde,PPTE pptekernel,PPTE pptepcb,PPROCESS pprocess)
{
   
	S4B i;
	for(i=0;i<256;i++) //the first 1G is for the kernel
		 ppde->pde[i]=3;
	for(i=256;i<1024;i++) //the remain 3G is for the user 
		 ppde->pde[i]=6;
	for(i=0;i<1024;i++) 
		 pptekernel->pte[i]=(i*(0x1000))+3;
//
        ppde->pde[0]=(((U4B)pptekernel)&0xFFFFF000)+3;
 //Print("the bad :%X ",ppde->pde[ ((U4B)202450)>>22]);
	ppde->pde[((U4B)pprocess)>>22]=(((U4B)pptepcb)&0xFFFFF000)+3;
      //  Print("%X ",ppde->pde[((U4B)pprocess)>>22]);
	pptepcb->pte[((((U4B)pprocess)>>12)&0x3FF)]=(((U4B)pprocess)&((U4B)0xFFFFF000))+3;

   //    Print(" %X ",pprocess);
    //    Print(" %X ",ppde->pde[((U4B)pprocess)>>22]);
    //    Print(" %X ",pptepcb->pte[((((U4B)pprocess)>>12)&0x3FF)]);
       // Print("the process:%X ",ppde->pde[((U4B)pprocess)>>22]);
    return ARTIST_ERROR_OK;
}


